package cn.tedu.charging.device.controller;

import cn.tedu.charging.common.pojo.query.NearStationsQuery;
import cn.tedu.charging.common.pojo.vo.StationDetailVO;
import cn.tedu.charging.common.pojo.vo.StationInfoVO;
import cn.tedu.charging.common.protocol.JsonResult;
import cn.tedu.charging.device.service.DeviceService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 站场 桩 枪接口全都集中在设备controller
 */
@RestController
@Slf4j
public class DeviceController {

    private final DeviceService deviceService;
    @Autowired
    public DeviceController(DeviceService deviceService) {
        this.deviceService = deviceService;
    }
    @GetMapping("/device/station/near")
    public JsonResult<List<StationInfoVO>> nearStations(NearStationsQuery query){
        List<StationInfoVO> result = deviceService.nearStations(query);
        return JsonResult.ok(result);
    }
    //查询某个充电站详情包括站场信息以及站场关联的枪数据
    @GetMapping("/device/station/detail/{stationId}")
    public JsonResult<StationDetailVO> detailStation(@PathVariable Integer stationId){
        StationDetailVO result = deviceService.detailStation(stationId);
        return JsonResult.ok(result);
    }
    //订单调用设备检查枪是否可用
    @GetMapping("/device/gun/check")
    public JsonResult<Boolean> checkGun(@RequestParam("gunId") Integer gunId){
        Boolean result = deviceService.checkGun(gunId);
        return JsonResult.ok(result);
    }

    @PostMapping("/device/gun/{id}/{status}")
    public JsonResult<Void> changeGunStatus(@PathVariable Integer id,@PathVariable Integer status){
        deviceService.changeGunStatus(id, status);
        return JsonResult.ok();
    }
}
